<template>
    <div>
        <div v-for="(value,key) in list">
            <div :style="{left:num*leftJl+`px`,width:`calc(100% - ${num*leftJl}px)`}" class="con" @click="add(value)">
                <div class="data">
                    <span>用户名:{{value.real_name || '暂无'}}&nbsp&nbsp</span>
                    <span>电话:{{value.phone}}&nbsp&nbsp</span>
                    <span>直推人数:{{value.p_num}}&nbsp&nbsp</span>
<!--                    <span>业绩:{{value.yeji}}&nbsp&nbsp</span>-->
                    <span>团队人数:{{value.team_num}}&nbsp&nbsp</span>
<!--                    <span>矿机数量:{{value.project_num}}&nbsp&nbsp</span>-->
                    <span>注册时间:{{timeFormat(value.add_time)}}&nbsp&nbsp</span>

                </div>
            </div>
            <mytree :list="value.children" :num="num+1"></mytree>
        </div>
    </div>

</template>


<script>
    export default {
        name: "tree",
        props: {
            list: {
                type: Array,
                default: () => {
                    return []
                }
            },
            num: {
                type: Number,
                default: 0,
            },
            leftJl: {
                type: Number,
                default: 30
            }
        },
        methods: {
            // add(val){
            //     console.log(val)
            //     if(val.isShow){
            //         val.children = []
            //         val.isShow = false
            //         return;
            //     }
            //     this.getJsonData('User/getInivt',{username:val.username}).then((res)=>{
            //         if(!val.isShow){
            //             val.children = res.user
            //         }else{
            //             val.children = []
            //             this.$Message.info('暂无下级')
            //         }
            //
            //         val.isShow = !val.isShow
            //     })
            // }
            add(val) {
                // console.log(val)
                if (val.children == '') {
                    this.getJsonData('User/getInivt', {username: val.username}).then((res) => {
                        if (res.user == '')  {
                            val.children = []
                            this.$Message.info('暂无下级')
                        }
                        else{
                            val.children = res.user.map((value)=>{
                                value.children = []
                                // value.isShow = false
                                return value
                            })
                        }

                        // val.isShow = !val.isShow
                    })
                }
                else {
                    val.children = []
                    // val.isShow = false
                    return;

                }
            }
        }
    }
</script>

<style scoped lang="less">
    .con {
        height: 40px;
        border: 1px solid red;
        border-radius: 4px;
        margin-bottom: 10px;
        line-height: 40px;
        text-indent: 20px;
        cursor: pointer;
        position: relative;
        .data {
            span {
                margin-right: 5px;
            }
        }
    }
</style>